package com.vieewer.btdemo.view.notification;

import android.app.Notification
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.graphics.BitmapFactory
import android.widget.RemoteViews
import android.app.NotificationManager
import android.app.NotificationChannel
import android.content.Context
import com.vieewer.btdemo.R
import com.vieewer.btdemo.base.BaseActivity
import kotlinx.android.synthetic.main.activity_test_notification.*


class TestNotificationActivity : BaseActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_test_notification)

        txt_test_notification.setOnClickListener {
            //1.获取系统通知的管理者
            var notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
            //2.初始化一个notification的对象
            var mBuilder = Notification.Builder(this)
            //android 8.0 适配     需要配置 通知渠道NotificationChannel
            var b: NotificationChannel
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
                b = NotificationChannel("1", "乱七八糟的其他信息", NotificationManager.IMPORTANCE_MIN)
                notificationManager.createNotificationChannel(b)
                mBuilder.setChannelId("1")
            }
            //添加自定义视图  activity_notification
            var mRemoteViews = RemoteViews(packageName, R.layout.layout_widget_notification)
            //主要设置setContent参数  其他参数 按需设置
            mBuilder.setContent(mRemoteViews)
            mBuilder.setSmallIcon(R.drawable.icon_weixin)
            mBuilder.setOngoing(true)
            mBuilder.setLargeIcon(BitmapFactory.decodeResource(resources, R.drawable.icon_weixin_round))
            mBuilder.setAutoCancel(true)
            //更新Notification
            notificationManager.notify(1, mBuilder.build())
        }


    }




}
